﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using psafth.Common.Extensions;

namespace psafth.AMB
{
    public class Status
    {
        /// <summary>
        /// Not sure if this really is a decoderid. 
        /// </summary>
        public int DecoderId
        {
            get;
            private set;
        }

        /// <summary>
        /// Input noise from the antenna
        /// </summary>
        public int Noise
        {
            get;
            private set;
        }

        /// <summary>
        /// Input voltage to the decoder
        /// </summary>
        public float InputVoltage
        {
            get;
            private set;
        }

        /// <summary>
        /// Temperature for the decoder
        /// </summary>
        public int Temperature
        {
            get;
            private set;
        }

        /// <summary>
        /// Constructs a StatusObject from the FOR
        /// </summary>
        /// <param name="fieldOfRecords"></param>
        public Status(List<DataRowObject> fieldOfRecords)
        {
            foreach (DataRowObject record in fieldOfRecords)
            {
                switch (record.DataType)
                {
                    case (int)AMBGeneralFOR.DECODER_ID:
                        if (record.Data != null)
                            this.DecoderId = record.Data.ToInt32();
                        break;

                    case (int)AMBStatusFOR.NOISE:
                        if (record.Data != null)
                            this.Noise = record.Data.ToInt32();
                        break;

                    case (int)AMBStatusFOR.INPUT_VOLTAGE:
                        if (record.Data != null)
                            this.InputVoltage = record.Data.ToInt32() / 10;
                        break;

                    case (int)AMBStatusFOR.TEMPERATURE:
                        if (record.Data != null)
                            this.Temperature = record.Data.ToInt32();
                        break;
                }
            }
        }
    }
}
